<?php
/**
* @file $Id: GetStaffList.fnc.php 287 2006-11-15 04:04:29Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

function GetStaffList($extra)
{
	switch(User('PROFILE'))
	{	
		case 'admin':
		$sql = "SELECT 
					COALESCE(s.LAST_NAME,' ')||', '||COALESCE(s.FIRST_NAME,' ')||' '||COALESCE(s.MIDDLE_NAME,' ') AS FULL_NAME,
					s.STAFF_ID,s.SCHOOLS,s.PROFILE_ID,s.PROFILE,s.USERNAME
				FROM 
					USERS s
				WHERE 
					s.SYEAR='".UserSyear()."'";
		if($_REQUEST['_search_all_schools']!='Y' && (!$_REQUEST['profile'] || $_REQUEST['profile']!='parent'))
			$sql .= " AND (s.SCHOOLS LIKE '%,".UserSchool().",%' OR s.SCHOOLS IS NULL OR s.SCHOOLS='') ";
		if($_REQUEST['username'])
			$sql .= "AND UPPER(s.USERNAME) LIKE '".strtoupper($_REQUEST['username'])."%' ";
		if($_REQUEST['last'])
			$sql .= "AND UPPER(s.LAST_NAME) LIKE '".strtoupper($_REQUEST['last'])."%' ";
		if($_REQUEST['first'])
			$sql .= "AND UPPER(s.FIRST_NAME) LIKE '".strtoupper($_REQUEST['first'])."%' ";
		if($_REQUEST['profile'])
			$sql .= "AND s.PROFILE='".$_REQUEST['profile']."' ";
			
		$sql .= "ORDER BY FULL_NAME";
	
		return DBGet(DBQuery($sql),$extra['functions']);
		break;
	}
}
?>